/*
 * @Author: chen haoxuan
 * @Date: 2021-06-05 21:59:52
 * @LastEditTime: 2021-06-05 22:22:01
 */
// 有子对象的派生类的构造函数
#include <iostream>
#include <string>
using namespace std;
class Student
{
public:
  Student(int n, string nam)
  {
    num = n;
    name = nam;
  }
  void display()
  {
    cout<<"num: "<<num<<"name: "<<name<<endl;
  }
protected:
  int num;
  string name;
};
class Student1 : public Student
{
public:
  Student1(int n, string nam, int n1, string nam1, int a, string ad) : Student(n, nam), monitor(n1, nam1)
  {
    age = a;
    addr = ad;
  }
  void show()
  {
    cout<<"This student is: "<<endl;
    display();
    cout<<"age: "<<age<<endl;
    cout<<"addr: "<<addr<<endl;
  }
  void show_monitor()
  {
    cout<<endl<<"class monitor is: "<<endl;
    monitor.display();
  }
private:
  Student monitor;
  int age;
  string addr;
};
int main()
{
  Student1 stud1(10010,"wang-li",10001,"li-hua",19,"beijing");
  stud1.show();
  stud1.show_monitor();
  system("pause");
  return 0;
}
/*
  构造函数执行顺序：
    (1) 调用基类构造函数，对基类数据成员初始化
    (2) 调用子对象构造函数，对子对象数据成员初始化
    (3) 执行派生类构造函数本身，对派生类的数据成员进行初始化
*/